<template>
    <div>
        <div class="block text-center" m="t-4">
            <el-carousel height="465px">
                <el-carousel-item v-for="item in swiperList" :key="item.id">
                    <img :src="item.pcAdvertiseUrl" alt="" width="1200" />
                </el-carousel-item>
            </el-carousel>
        </div>
        <div class="midNav">
            <ul class="midNav-ul" ref="midNavUlRef">
                <router-link to="recommend" exact>
                    <li>推荐</li>
                </router-link>
                <router-link to="original" exact>
                    <li>作品</li>
                </router-link>

                <router-link to="course" exact>
                    <li>教程</li>
                </router-link>

                <router-link to="specialTopic" exact>
                    <li>专题</li>
                </router-link>

                <router-link to="information" exact>
                    <li>动态</li>
                </router-link>

                <router-link to="attention" exact>
                    <li>关注</li>
                </router-link>
                <li v-for="item in interesTagList" :key="item.id">{{ item.name }}</li>
            </ul>
            <div class="instrestBread" @click="dialogVisible = true">
                <el-icon class="instrestBread-el-icon" :size="20"><Grid /></el-icon>
                <span>选择兴趣技能</span>
            </div>
        </div>
        <div class="content">
            <router-view></router-view>
        </div>
        <!-- 弹出框 -->
        <el-dialog class="el-dialog-box" title="选择我的兴趣技能" width="70%" v-model="dialogVisible">
            <span>例如舞蹈就选舞种</span>
            <br />
            <el-input
                style="margin-top: 20px; width: 180px"
                class="w-50 m-2"
                size="large"
                placeholder="搜索兴趣技能"
                :prefix-icon="Search"
                v-model="searchValueNow"
            />
            <el-button @click="search" plain size="large" style="margin-top: 20px; margin-left: 20px">搜索</el-button>
            <br />
            <p style="margin-top: 20px">推荐兴趣技能</p>

            <!-- 搜索结果 -->

            <div class="searchResult" v-if="searchIsShow === true">
                <div>
                    <div class="searchItem" v-for="item in searchInterestList" :key="item.id" @click="addTag(item)">
                        <div class="searchItemLeft">
                            <div class="searchItemLeftBox">
                                <el-icon :size="25"><BellFilled /></el-icon>
                            </div>
                        </div>
                        <div class="searchItemMid">
                            <br />
                            <div class="searchItemMidTop">{{ item.name }}</div>
                            <div class="searchItemMidBottom">{{ item.description }}</div>
                        </div>
                        <div class="searchItemRight">
                            <el-icon :size="25"><FolderAdd /></el-icon>
                        </div>
                    </div>
                </div>
            </div>
            <!-- 兴趣列表展示 -->
            <div v-if="searchIsShow === false">
                <div>
                    <el-tag
                        v-for="(item, index) in interesTagList"
                        :key="item.id"
                        class="selectedInteresItem"
                        @click="deleteTag(index)"
                        >{{ item.name }}</el-tag
                    >
                </div>
                <div infinite-scroll-distance="1" v-infinite-scroll="load" class="infinite-list" style="overflow: auto">
                    <el-tag v-for="item in tagList" :key="item.id" class="infinite-list-item" @click="addTag(item)">{{
                        item.name
                    }}</el-tag>
                </div>
            </div>

            <template #footer>
                <span class="dialog-footer">
                    <el-button class="cancel" size="large" @click="dialogVisible = false">取消</el-button>
                    <el-button class="confrim" size="large" type="primary" @click="dialogVisible = false">
                        确定
                    </el-button>
                </span>
            </template>
        </el-dialog>
    </div>
</template>

<script lang="ts">
import { defineComponent } from "vue";
import { ElMessage, ElNotification } from "element-plus";

export default defineComponent({
    name: "Index",
});
</script>

<script setup lang="ts">
import { onMounted, ref } from "vue";
import { Search } from "@element-plus/icons-vue";
import { useIndexStore } from "@/store/modules/index/index";
import { storeToRefs } from "pinia";
import type { tagListType, tagType } from "@/api/index/interface";

const dialogVisible = ref(false);

// 轮播图
const { getSwiperListAsync } = useIndexStore();
const { swiperList } = storeToRefs(useIndexStore());
onMounted(() => {
    getSwiperListAsync();
});

//兴趣列表
const { getInterestListAsync, getNewInterestListAsync } = useIndexStore();
const { tagList, interesTagList } = storeToRefs(useIndexStore());
onMounted(() => {
    getInterestListAsync(1, 20);
});
// 兴趣列表tag加载
const pageNum = ref(1);

const load = () => {
    pageNum.value++;
    getNewInterestListAsync(pageNum.value, 8);
};
// 兴趣列表已选中

const addTag = (tag: any) => {
    if (interesTagList.value.length <= 4) {
        tag.description = "";
        interesTagList.value.push(tag);
        searchIsShow.value = false;
    } else {
        console.log("最多选5个");
    }
};
const deleteTag = (index: number) => {
    interesTagList.value.splice(index, 1);
};
// 兴趣列表搜索
const { getSearchInterest } = useIndexStore();
const { searchInterestList } = storeToRefs(useIndexStore());

const search = () => {
    getSearchInterest(searchValueNow.value);
    searchIsShow.value = true;
};
const searchValueNow = ref<string>("");
const searchIsShow = ref<boolean>(false);
</script>

<style lang="less" scoped>
.block,
.text-center {
    margin-top: 20px;
    border-radius: 5px;
    overflow: hidden;
}
.midNav {
    position: relative;
    height: 80px;
    display: flex;
    justify-content: center;
    align-items: center;
    .midNav-ul {
        .router-link-active {
            li {
                border-bottom: 2px #111 solid;

                color: #111;
            }
        }
        li {
            float: left;
            margin: 0 20px;
            height: 76px;
            line-height: 80px;

            font-size: 16px;
            color: #7e808f;
            &:hover {
                cursor: pointer;
                color: #111;
            }
        }
    }
    .instrestBread {
        position: absolute;
        right: 0;
        span {
            font-size: 16px;
            color: #7e808f;
        }
        &:hover {
            cursor: pointer;
        }
        .instrestBread-el-icon {
            color: #7e808f;
            position: absolute;
            right: 110px;
        }
    }
}
// 弹出框
.el-dialog-box {
    .selectedInteresItem {
        width: 100px;
        height: 40px;
        margin: 20px 10px;
        border-color: #eaecf0;
        background-color: #fff;
        color: #111;
    }
    .searchResult {
        display: flex;
        justify-content: space-between;
        flex-wrap: wrap;
        .searchItem {
            display: inline-block;
            background-color: #f5f7f9;
            width: 300px;
            height: 70px;
            margin: 10px 10px;
            .searchItemLeft {
                width: 60px;
                height: 100%;
                float: left;

                display: flex;
                justify-content: center;
                align-items: center;
                .searchItemLeftBox {
                    width: 40px;
                    height: 40px;
                    background-color: #fff;
                    display: flex;
                    justify-content: center;
                    align-items: center;
                }
            }
            .searchItemMid {
                height: 100%;
                width: 200px;
                float: left;
                .searchItemMidTop {
                    color: #111;
                    padding-bottom: 10px;
                }
                .searchItemMidBottom {
                    color: #848594;
                }
            }
            .searchItemRight {
                display: flex;
                justify-content: center;
                align-items: center;
                float: left;
                height: 100%;
                width: 40px;
            }
        }
    }
    .dialog-footer {
        .cancel {
            border-color: #dddfe5;
            width: 130px;
        }
        .confrim {
            background-color: #e54983;
            width: 130px;

            border-color: #dddfe5;
        }
    }
}
</style>

<style lang="less">
.infinite-list {
    height: 300px;
    padding: 0;
    margin: 0;
    margin-top: 20px;
    list-style: none;
    display: flex;
    flex-wrap: wrap;
}
.infinite-list .infinite-list-item {
    width: 100px;
    height: 40px;
    margin: 20px 10px;
    border-color: #eaecf0;
    background-color: #fff;
    color: #111;
}
.infinite-list .infinite-list-item + .list-item {
    margin-top: 10px;
}
</style>
